import { getChannelListAPI } from "@/apis/article";
import { Select } from "antd";
import { useEffect, useState } from "react";
function ChannelSelect() {
  // 下拉列表框频道数据
  const [channelList, setChannelList] = useState([]);

  // 获取频道列表数据并存储
  const getChannelList = async () => {
    const result = await getChannelListAPI();
    setChannelList(
      result.data.channels.map((item) => {
        return {
          label: item.name, // 下拉列表框显示的文字
          value: item.id, // 下拉列表框的值
        };
      })
    );
  };
  // 组件渲染完毕获取频道列表数据
  useEffect(() => {
    getChannelList();
  }, []);
  return (
    <>
      <Select
        placeholder="请选择文章频道"
        style={{
          width: 140,
        }}
        options={channelList}
      />
    </>
  );
}

export default ChannelSelect;
